<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="com.riq.entity.Member"%>
<%@ page import="com.riq.entity.Department"%>
<%@ page import="java.util.logging.Logger"%>
<%@ page import="java.io.IOException"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.util.Date"%>

<%
  List<Department> allDepts = (List<Department>) request.getAttribute("allDepts");
  List<Member> membersRangeA = (List<Member>) request.getAttribute("membersRangeA");
  List<Member> membersRangeB = (List<Member>) request.getAttribute("membersRangeB");
  List<Member> membersRangeC = (List<Member>) request.getAttribute("membersRangeC");
  List<Member> membersRangeD = (List<Member>) request.getAttribute("membersRangeD");
  List<Member> membersRangeX = (List<Member>) request.getAttribute("membersRangeX");

  String cellColorRangeA = "";
  String cellColorRangeB = "";
  String cellColorRangeC = "";
  String cellColorRangeD = "";
  String cellColorRangeX = "";

  // TODO: make these "dept configurable" someday...

  int lowCountA = 6; int lowCountB = 4; int lowCountC = 2; int lowCountD = 0;
  int midCountA = 8; int midCountB = 6; int midCountC = 4; int midCountD = 2;
  int uppCountA = 9; int uppCountB = 8; int uppCountC = 6; int uppCountD = 4;
  
  long aT = 0; long dTA = 0; long DmA = 0; long HmA = 0; long MmA = 0;
  long bT = 0; long dTB = 0; long DmB = 0; long HmB = 0; long MmB = 0;
  long cT = 0; long dTC = 0; long DmC = 0; long HmC = 0; long MmC = 0;
  long dT = 0; long dTD = 0; long DmD = 0; long HmD = 0; long MmD = 0;
  long xT = 0; long dTX = 0; long DmX = 0; long HmX = 0; long MmX = 0;

  // use variables above to compute status resulting in different colored table cells
  int sizeA = membersRangeA.size();
  // Colors for Count Cell Based on Number of Responders
  if (sizeA < lowCountA) {
    cellColorRangeA = "medium right red";
  } else if (sizeA < midCountA) {
    cellColorRangeA = "medium right yellow";
  } else {
    cellColorRangeA = "medium right green";
  }

  int sizeB = membersRangeB.size();
  // Colors for Count Cell Based on Number of Responders
  if (sizeB < lowCountB) {
    cellColorRangeB = "medium right red";
  } else if (sizeB < midCountB) {
    cellColorRangeB = "medium right yellow";
  } else {
    cellColorRangeB = "medium right green";
  }

  int sizeC = membersRangeC.size();
  // Colors for Count Cell Based on Number of Responders
  if (sizeC < lowCountC) {
    cellColorRangeC = "medium right red";
  } else if (sizeC < midCountC) {
    cellColorRangeC = "medium right yellow";
  } else {
    cellColorRangeC = "medium right green";
  }

  int sizeD = membersRangeD.size();
  cellColorRangeD = "medium right gray";

  int sizeX = membersRangeX.size();
  cellColorRangeX = "medium right gray";

  // Next would be to create scoring based on type e.g. Chief > 1 = 10 points, 
  // Captain Count > 2 = 10 points ...
%>
<!-- Copyright 2010 John L. Reilly

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.   -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>FirstResponder</title>

<!--META-->
<meta http-equiv="content-type"  content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width" />

<!--STYLESHEET-->
<link rel="stylesheet" type="text/css" href="stylesheets/static.css" />
</head>

<body>
<!--FIXED HEADERS-->
<div class="headwrap">
<div class="hBlack">
<div class="headerLeftTop">FirstResponder</div>
<div class="headerRightTop">ver 0.9</div>
<div class="headerLeftBottom">Readiness</div>
<div class="headerRightBottom">Main</div>
</div>
<div class="hGray">
  <a class="buttonGrayHdr gSelected" href="mainMenu.html">Main</a>
  <a class="buttonGrayHdr" href="commandMenu.html">Command</a>
  <a class="buttonGrayHdr" href="department?action=display">Admin</a>
</div>
<div class="headerMist"></div>
</div> 

<div class="outwrap">
<div class="headerPlug"></div>

<!--BUTTONS-->
<div id="centeredButtons"><ul><li>
<a class="button blue narrow tall first last"
   href="department?action=polling&mutualAid=no">Primary Dept</a>
   </li><li>
<a class="button blue narrow tall first last" 
   href="department?action=polling&mutualAid=yes">Mutual Aid</a></li></ul></div>

<%
   if (allDepts.equals(null)) {
%>

<div class="sub black">Dept: No Depts Listed</div>

<%
  } else {
    
    for (Department d : allDepts) {
%>
<div class="sub black">DEPT: <%=d.getshortName().toUpperCase()%></div>

<!--RANGE A-->
<div class="sub white">
0-<%=d.getdistGroupA()%> MINUTES </div>
<%  if (!membersRangeA.isEmpty()) {
      for (Member mA : membersRangeA) {
         if (mA.getdeptId().equals(d.getid())) {
              aT = System.currentTimeMillis() / 1000;
              dTA = mA.getdistTimeStamp();
              DmA = (aT - dTA) / 60 / 60 / 24;
              HmA = ((aT - dTA) - (DmA * 60 * 60 * 24)) / 60 / 60;
              MmA = ((aT - dTA) - (DmA * 60 * 60 * 24) - (HmA * 60 * 60)) / 60; %>
              <div class="row">
              <%=mA.getfirstName()%> <%=mA.getlastName()%> 
              (Last Reading: <%=DmA%>:<%=HmA%>:<%=MmA%>)</div>
              <% }}} %>

<!--RANGE B-->
<div class="sub white">
<%=d.getdistGroupA()%>-<%=d.getdistGroupB()%> MINUTES </div>
<%  if (!membersRangeB.isEmpty()) {
      for (Member mB : membersRangeB) {
        if (mB.getdeptId().equals(d.getid())) {
          bT = System.currentTimeMillis() / 1000;
          dTB = mB.getdistTimeStamp();
          DmB = (bT - dTB) / 60 / 60 / 24;
          HmB = ((bT - dTB) - (DmB * 60 * 60 * 24)) / 60 / 60;
          MmB = ((bT - dTB) - (DmB * 60 * 60 * 24) - (HmB * 60 * 60)) / 60;%>
          <div class="row">
          <%=mB.getfirstName()%> <%=mB.getlastName()%> </div>
          <% }}} %>

<!--RANGE C-->
<div class="sub white">
<%=d.getdistGroupB()%>-<%=d.getdistGroupC()%>  MINUTES </div>
<% if (!membersRangeC.isEmpty()) {
    for (Member mC : membersRangeC) {
      if (mC.getdeptId().equals(d.getid())) {
        cT = System.currentTimeMillis() / 1000;
        dTC = mC.getdistTimeStamp();
        DmC = (cT - dTC) / 60 / 60 / 24;
        HmC = ((cT - dTC) - (DmC * 60 * 60 * 24)) / 60 / 60;
        MmC = ((cT - dTC) - (DmC * 60 * 60 * 24) - (HmC * 60 * 60)) / 60;%>
        <div class="row">
        <%=mC.getfirstName()%> <%=mC.getlastName()%></div>
        <% }}} %>

<!--RANGE D-->
<div class="sub white"> 
<%=d.getdistGroupC()%>+  MINUTES </div>
<% if (!membersRangeD.isEmpty()) {
    for (Member mD : membersRangeD) {
      if (mD.getdeptId().equals(d.getid())) {
        dT = System.currentTimeMillis() / 1000;
        dTD = mD.getdistTimeStamp();
        DmD = (dT - dTD) / 60 / 60 / 24;
        HmD = ((dT - dTD) - (DmD * 60 * 60 * 24)) / 60 / 60;
        MmD = ((dT - dTD) - (DmD * 60 * 60 * 24) - (HmD * 60 * 60)) / 60;%>
        <div class="row">
        <%=mD.getfirstName()%> <%=mD.getlastName()%> </div>
        <% }}} %>

<!--RANGE X -->
<div class="sub white">
UNKNOWN
<div class="right"> <%=sizeX%></div></div>
<% if (!membersRangeX.isEmpty()) {
    for (Member mX : membersRangeX) {
      if (mX.getdeptId().equals(d.getid())) {
        xT = System.currentTimeMillis() / 1000;
        dTX = mX.getdistTimeStamp();
        DmX = (xT - dTX) / 60 / 60 / 24;
        HmX = ((xT - dTX) - (DmX * 60 * 60 * 24)) / 60 / 60;
        MmX = ((xT - dTX) - (DmX * 60 * 60 * 24) - (HmX * 60 * 60)) / 60;%>
        <div class="row">
        <%=mX.getfirstName()%> <%=mX.getlastName()%> <%
        if (DmX < 10000) { %> % } else { %> (TBD) <% } %>
        </div>
        <% }}}
}} %>

<!--FOOTER-->
<div class="footer">FirstResponder</div>

<!--OUTLINE WRAPPER -->
</div> 

</body>
</html>
